/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.dog.dao.impl;

import com.dog.dao.VacancyDAO;
import com.dog.model.Vacancy;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import javax.annotation.PostConstruct;

/**
 * User: Kuttubek Aidaraliev
 * Date: 02.04.2010
 * Time: 08:52:04
 */

@Repository
public class VacancyDAOImpl extends DAOImpl<Vacancy> implements VacancyDAO {

    @Autowired
    private SessionFactory sessionFactory;

    public VacancyDAOImpl() {
        super(Vacancy.class);
    }

    @PostConstruct
    private void initialize() {
        this.setSessionFactory(sessionFactory);
    }

    @Override
    public Vacancy getByIdWithContactPersons(Long vacancyId) {
        String sql = "select distinct vacancy from Vacancy as vacancy " +
                " left join fetch vacancy.contactPersons" +
                " where vacancy.id=?";
        return findUnique(sql, vacancyId);
    }
}
